<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="JavaScript," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="设置节点属性获取节点属性123getAttribute(属性)      获取属性     通过这个方法，可以得到 某些元素的  某些属性 。alert(demo.getAttribute(&quot;title&quot;)); 设置节点属性123setAttribute(“属性”,”值”);    比如说，我们想要把 一个 类名  改为   demo     div.setAttribute(“class”,”d">
<meta name="keywords" content="JavaScript">
<meta property="og:type" content="article">
<meta property="og:title" content="前端JavaScript（二）">
<meta property="og:url" content="http://yoursite.com/2016/11/29/前端JavaScript（二）/index.html">
<meta property="og:site_name" content="JokerLiang">
<meta property="og:description" content="设置节点属性获取节点属性123getAttribute(属性)      获取属性     通过这个方法，可以得到 某些元素的  某些属性 。alert(demo.getAttribute(&quot;title&quot;)); 设置节点属性123setAttribute(“属性”,”值”);    比如说，我们想要把 一个 类名  改为   demo     div.setAttribute(“class”,”d">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2016-11-30T10:06:14.868Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="前端JavaScript（二）">
<meta name="twitter:description" content="设置节点属性获取节点属性123getAttribute(属性)      获取属性     通过这个方法，可以得到 某些元素的  某些属性 。alert(demo.getAttribute(&quot;title&quot;)); 设置节点属性123setAttribute(“属性”,”值”);    比如说，我们想要把 一个 类名  改为   demo     div.setAttribute(“class”,”d">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2016/11/29/前端JavaScript（二）/"/>





  <title> 前端JavaScript（二） | JokerLiang </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  








  <div style="display: none;">
    <script src="//s95.cnzz.com/z_stat.php?id=1260895995&web_id=1260895995" language="JavaScript"></script>
  </div>





  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">JokerLiang</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">永远年轻，永远热泪盈眶。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>


    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://yoursite.com/2016/11/29/前端JavaScript（二）/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="JokerLiang">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/me.jpg">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="JokerLiang">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="JokerLiang" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                前端JavaScript（二）
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2016-11-29T19:48:16+08:00">
                2016-11-29
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/前端基本功/" itemprop="url" rel="index">
                    <span itemprop="name">前端基本功</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="&#x8BBE;&#x7F6E;&#x8282;&#x70B9;&#x5C5E;&#x6027;"><a href="#&#x8BBE;&#x7F6E;&#x8282;&#x70B9;&#x5C5E;&#x6027;" class="headerlink" title="&#x8BBE;&#x7F6E;&#x8282;&#x70B9;&#x5C5E;&#x6027;"></a>&#x8BBE;&#x7F6E;&#x8282;&#x70B9;&#x5C5E;&#x6027;</h2><h3 id="&#x83B7;&#x53D6;&#x8282;&#x70B9;&#x5C5E;&#x6027;"><a href="#&#x83B7;&#x53D6;&#x8282;&#x70B9;&#x5C5E;&#x6027;" class="headerlink" title="&#x83B7;&#x53D6;&#x8282;&#x70B9;&#x5C5E;&#x6027;"></a>&#x83B7;&#x53D6;&#x8282;&#x70B9;&#x5C5E;&#x6027;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">getAttribute(&#x5C5E;&#x6027;)      &#x83B7;&#x53D6;&#x5C5E;&#x6027;     </span><br><span class="line">&#x901A;&#x8FC7;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x5F97;&#x5230; &#x67D0;&#x4E9B;&#x5143;&#x7D20;&#x7684;  &#x67D0;&#x4E9B;&#x5C5E;&#x6027; &#x3002;</span><br><span class="line">alert(demo.getAttribute(<span class="string">&quot;title&quot;</span>));</span><br></pre></td></tr></table></figure>
<h3 id="&#x8BBE;&#x7F6E;&#x8282;&#x70B9;&#x5C5E;&#x6027;-1"><a href="#&#x8BBE;&#x7F6E;&#x8282;&#x70B9;&#x5C5E;&#x6027;-1" class="headerlink" title="&#x8BBE;&#x7F6E;&#x8282;&#x70B9;&#x5C5E;&#x6027;"></a>&#x8BBE;&#x7F6E;&#x8282;&#x70B9;&#x5C5E;&#x6027;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">setAttribute(&#x201C;&#x5C5E;&#x6027;&#x201D;,&#x201D;&#x503C;&#x201D;);</span><br><span class="line">    &#x6BD4;&#x5982;&#x8BF4;&#xFF0C;&#x6211;&#x4EEC;&#x60F3;&#x8981;&#x628A; &#x4E00;&#x4E2A; &#x7C7B;&#x540D;  &#x6539;&#x4E3A;   demo  </span><br><span class="line">   div.setAttribute(&#x201C;<span class="class"><span class="keyword">class</span>&#x201D;,&#x201D;<span class="title">demo</span>&#x201D;)</span>;</span><br></pre></td></tr></table></figure>
<h3 id="&#x5220;&#x9664;&#x67D0;&#x4E2A;&#x5C5E;&#x6027;"><a href="#&#x5220;&#x9664;&#x67D0;&#x4E2A;&#x5C5E;&#x6027;" class="headerlink" title="&#x5220;&#x9664;&#x67D0;&#x4E2A;&#x5C5E;&#x6027;"></a>&#x5220;&#x9664;&#x67D0;&#x4E2A;&#x5C5E;&#x6027;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">removeAttribute(&#x201C;&#x5C5E;&#x6027;&#x201D;); </span><br><span class="line">demo.removeAttribute(&#x201C;title&#x201D;)  </span><br><span class="line">&#x8FD9;&#x4E2A;&#x76D2;&#x5B50;&#x5C31;&#x6CA1;&#x6709;title  &#x5C5E;&#x6027;  &#x7ED9;&#x5220;&#x6389;&#x4E86;</span><br></pre></td></tr></table></figure>
<h2 id="&#x65E5;&#x671F;&#x51FD;&#x6570;"><a href="#&#x65E5;&#x671F;&#x51FD;&#x6570;" class="headerlink" title="&#x65E5;&#x671F;&#x51FD;&#x6570;"></a>&#x65E5;&#x671F;&#x51FD;&#x6570;</h2><p>&#x8FD9;&#x4E2A;&#x51FD;&#x6570; &#xFF08;&#x5BF9;&#x8C61;&#xFF09; &#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x6211;&#x4EEC;&#x672C;&#x5730; &#x65E5;&#x671F;&#x3002;   &#x5E74;&#x6708;&#x65E5; &#x65F6;&#x5206;&#x79D2;<br><a id="more"></a></p>
<h3 id="&#x58F0;&#x660E;&#x65E5;&#x671F;"><a href="#&#x58F0;&#x660E;&#x65E5;&#x671F;" class="headerlink" title="&#x58F0;&#x660E;&#x65E5;&#x671F;"></a>&#x58F0;&#x660E;&#x65E5;&#x671F;</h3><p>  var  date = new Date();<br>  &#x521B;&#x9020;&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x65E5;&#x671F;&#x51FD;&#x6570;   &#x8D4B;&#x503C;&#x7ED9;&#x4E86;  date </p>
<h3 id="&#x5E38;&#x7528;&#x7684;&#x65E5;&#x671F;&#x7684;&#x65B9;&#x6CD5;"><a href="#&#x5E38;&#x7528;&#x7684;&#x65E5;&#x671F;&#x7684;&#x65B9;&#x6CD5;" class="headerlink" title="&#x5E38;&#x7528;&#x7684;&#x65E5;&#x671F;&#x7684;&#x65B9;&#x6CD5;"></a>&#x5E38;&#x7528;&#x7684;&#x65E5;&#x671F;&#x7684;&#x65B9;&#x6CD5;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">getDate()                  &#x83B7;&#x53D6;&#x65E5; <span class="number">1</span><span class="number">-31</span></span><br><span class="line">getDay ()                  &#x83B7;&#x53D6;&#x661F;&#x671F; <span class="number">0</span><span class="number">-6</span>      </span><br><span class="line">getMonth ()                &#x83B7;&#x53D6;&#x6708;  <span class="number">0</span><span class="number">-11</span></span><br><span class="line">getFullYear ()	            &#x83B7;&#x53D6;&#x5B8C;&#x6574;&#x5E74;&#x4EFD;&#xFF08;&#x6D4F;&#x89C8;&#x5668;&#x90FD;&#x652F;&#x6301;&#xFF09;</span><br><span class="line">getHours ()	               &#x83B7;&#x53D6;&#x5C0F;&#x65F6; <span class="number">0</span><span class="number">-23</span></span><br><span class="line">getMinutes ()	               &#x83B7;&#x53D6;&#x5206;&#x949F; <span class="number">0</span><span class="number">-59</span></span><br><span class="line">getSeconds ()	               &#x83B7;&#x53D6;&#x79D2;  <span class="number">0</span><span class="number">-59</span></span><br><span class="line">getMilliseconds ()            &#x83B7;&#x53D6;&#x5F53;&#x524D;&#x7684;&#x6BEB;&#x79D2; </span><br><span class="line">getTime ()	       &#x8FD4;&#x56DE;&#x7D2F;&#x8BA1;&#x6BEB;&#x79D2;&#x6570;(&#x4ECE;<span class="number">1970</span>/<span class="number">1</span>/<span class="number">1</span>&#x5348;&#x591C;)</span><br></pre></td></tr></table></figure>
<h3 id="&#x5012;&#x8BA1;&#x65F6;"><a href="#&#x5012;&#x8BA1;&#x65F6;" class="headerlink" title="&#x5012;&#x8BA1;&#x65F6;"></a>&#x5012;&#x8BA1;&#x65F6;</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span><span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">style</span>&gt;</span><span class="undefined"></span></span><br><span class="line"><span class="undefined">        body{</span></span><br><span class="line"><span class="undefined">            font-size:30px;</span></span><br><span class="line"><span class="undefined">            text-align: center;</span></span><br><span class="line"><span class="undefined">            color:red;</span></span><br><span class="line"><span class="undefined">        }</span></span><br><span class="line"><span class="undefined">    </span><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="undefined"></span></span><br><span class="line"><span class="javascript">        <span class="built_in">window</span>.onload = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>{</span></span><br><span class="line"><span class="javascript">            <span class="keyword">var</span> demo = <span class="built_in">document</span>.getElementById(<span class="string">&quot;demo&quot;</span>);</span></span><br><span class="line"><span class="javascript">            <span class="keyword">var</span> endTime = <span class="keyword">new</span> <span class="built_in">Date</span>(<span class="string">&quot;2015/12/12 17:30:00&quot;</span>); <span class="comment">// &#x6700;&#x7EC8;&#x65F6;&#x95F4;</span></span></span><br><span class="line"><span class="javascript">            setInterval(clock,<span class="number">1000</span>); <span class="comment">// &#x5F00;&#x542F;&#x5B9A;&#x65F6;&#x5668;</span></span></span><br><span class="line"><span class="javascript">            <span class="function"><span class="keyword">function</span> <span class="title">clock</span>(<span class="params"></span>)</span>{</span></span><br><span class="line"><span class="javascript">                <span class="keyword">var</span> nowTime = <span class="keyword">new</span> <span class="built_in">Date</span>(); <span class="comment">// &#x4E00;&#x5B9A;&#x662F;&#x8981;&#x83B7;&#x53D6;&#x6700;&#x65B0;&#x7684;&#x65F6;&#x95F4;</span></span></span><br><span class="line"><span class="javascript">                <span class="comment">//  console.log(nowTime.getTime());  &#x83B7;&#x5F97;&#x81EA;&#x5DF1;&#x7684;&#x6BEB;&#x79D2;</span></span></span><br><span class="line"><span class="javascript">                <span class="keyword">var</span> second = <span class="built_in">parseInt</span>((endTime.getTime() - nowTime.getTime()) / <span class="number">1000</span>);</span></span><br><span class="line"><span class="javascript">                <span class="comment">// &#x7528;&#x5C06;&#x6765;&#x7684;&#x65F6;&#x95F4;&#x6BEB;&#x79D2; -  &#x73B0;&#x5728;&#x7684;&#x6BEB;&#x79D2;  / 1000 &#x5F97;&#x5230;&#x7684; &#x8FD8;&#x5269;&#x4E0B;&#x7684;&#x79D2;  &#x53EF;&#x80FD;&#x5904;&#x4E0D;&#x65AD; &#x53D6;&#x6574;</span></span></span><br><span class="line"><span class="javascript">               <span class="comment">// console.log(second);</span></span></span><br><span class="line"><span class="javascript">                 <span class="comment">// &#x4E00;&#x5C0F;&#x65F6; 3600 &#x79D2;</span></span></span><br><span class="line"><span class="javascript">                <span class="comment">// second / 3600  &#x4E00;&#x5171;&#x7684;&#x5C0F;&#x65F6;&#x6570;  /24   &#x5929;&#x6570;</span></span></span><br><span class="line"><span class="javascript">                <span class="keyword">var</span> d = <span class="built_in">parseInt</span>(second / <span class="number">3600</span> / <span class="number">24</span>);  <span class="comment">//&#x5929;&#x6570;</span></span></span><br><span class="line"><span class="javascript">                <span class="comment">//console.log(d);</span></span></span><br><span class="line"><span class="javascript">                <span class="keyword">var</span> h = <span class="built_in">parseInt</span>(second / <span class="number">3600</span>  % <span class="number">24</span>)  <span class="comment">// &#x5C0F;&#x65F6;</span></span></span><br><span class="line"><span class="javascript">               <span class="comment">// console.log(h);</span></span></span><br><span class="line"><span class="javascript">                <span class="keyword">var</span> m = <span class="built_in">parseInt</span>(second / <span class="number">60</span>  % <span class="number">60</span>);</span></span><br><span class="line"><span class="javascript">                <span class="comment">//console.log(m);</span></span></span><br><span class="line"><span class="javascript">                <span class="keyword">var</span> s = <span class="built_in">parseInt</span>(second % <span class="number">60</span>); <span class="comment">// &#x5F53;&#x524D;&#x7684;&#x79D2;</span></span></span><br><span class="line"><span class="javascript">                <span class="built_in">console</span>.log(s);</span></span><br><span class="line"><span class="undefined">               /* if(d&lt;10)</span></span><br><span class="line"><span class="undefined">                {</span></span><br><span class="line"><span class="javascript">                    d = <span class="string">&quot;0&quot;</span> + d;</span></span><br><span class="line"><span class="undefined">                }*/</span></span><br><span class="line"><span class="javascript">                d&lt;<span class="number">10</span> ? d=<span class="string">&quot;0&quot;</span>+d : d;</span></span><br><span class="line"><span class="javascript">                h&lt;<span class="number">10</span> ? h=<span class="string">&quot;0&quot;</span>+h : h;</span></span><br><span class="line"><span class="javascript">                m&lt;<span class="number">10</span> ? m=<span class="string">&quot;0&quot;</span>+m : m;</span></span><br><span class="line"><span class="javascript">                s&lt;<span class="number">10</span> ? s=<span class="string">&quot;0&quot;</span>+s : s;</span></span><br><span class="line"><span class="javascript">                demo.innerHTML = <span class="string">&quot;&#x8DDD;&#x79BB;&#x62A2;&#x8D2D;&#x65F6;&#x95F4;&#x8FD8;&#x5269;: &quot;</span>+d+<span class="string">&quot;&#x5929; &quot;</span>+h+<span class="string">&quot;&#x5C0F;&#x65F6; &quot;</span>+m+<span class="string">&quot;&#x5206;&#x949F; &quot;</span>+s+<span class="string">&quot;&#x79D2;&quot;</span>;</span></span><br><span class="line"><span class="undefined">            }</span></span><br><span class="line"><span class="undefined">        }</span></span><br><span class="line"><span class="undefined">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;demo&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h2 id="&#x5B9A;&#x65F6;&#x5668;"><a href="#&#x5B9A;&#x65F6;&#x5668;" class="headerlink" title="&#x5B9A;&#x65F6;&#x5668;"></a>&#x5B9A;&#x65F6;&#x5668;</h2><h3 id="setInterval"><a href="#setInterval" class="headerlink" title="setInterval()"></a>setInterval()</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">setInterval(&#x201C;fun()&#x201D;,<span class="number">1000</span>)   </span><br><span class="line">setInterval( <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>{} , <span class="number">1000</span> )</span><br></pre></td></tr></table></figure>
<h3 id="setTimeout"><a href="#setTimeout" class="headerlink" title="setTimeout()"></a>setTimeout()</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"> setTimeout(&#x201C;&#x51FD;&#x6570;&#x201D;, &#x65F6;&#x95F4; )</span><br><span class="line">&#x53EA;&#x4F1A;&#x6267;&#x884C;&#x4E00;&#x6B21;&#x5982;&#x679C;&#x60F3;&#x8981;&#x5FAA;&#x73AF;&#xFF0C;&#x9700;&#x8981;&#x7528;&#x9012;&#x5F52;&#x5199;&#x6CD5;&#xFF08;&#x4E0B;&#x9762;&#xFF09;</span><br><span class="line"></span><br><span class="line">&lt;script&gt;</span><br><span class="line">    <span class="keyword">var</span> demo = <span class="built_in">document</span>.getElementById(<span class="string">&quot;demo&quot;</span>);</span><br><span class="line">    <span class="keyword">var</span> count = <span class="number">5</span>;</span><br><span class="line">    <span class="keyword">var</span> speed = <span class="number">1000</span>;</span><br><span class="line">    setTimeout(goIndexPage,speed);  <span class="comment">//  1&#x79D2;&#x949F;&#x4E4B;&#x540E;&#x53BB;&#x6267;&#x884C;  goIndexPage&#x8FD9;&#x4E2A;&#x51FD;&#x6570;</span></span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">goIndexPage</span>(<span class="params"></span>) </span>{</span><br><span class="line">        count--;</span><br><span class="line">        demo.innerHTML = <span class="string">&quot;&lt;a href=&apos;http://www.baidu.com&apos;&gt;&#x672C;&#x9875;&#x9762;&#x5C06;&#x5728;&#x7B2C;&quot;</span>+count+<span class="string">&quot;&#x79D2;&#x949F;&#x4E4B;&#x540E;&#x8DF3;&#x8F6C;&#x9875;&#x9762;&lt;/a&gt;&quot;</span>;</span><br><span class="line">        <span class="keyword">if</span>(count &lt;= <span class="number">0</span>)</span><br><span class="line">        {</span><br><span class="line">            <span class="comment">// &#x5982;&#x679C; count &#x5C0F;&#x4E8E; 0 &#x5C31;&#x5230;&#x4E86;&#x65F6;&#x95F4;&#x4E86;   &#x6211;&#x4EEC;&#x5E94;&#x8BE5;&#x8DF3;&#x8F6C;&#x9875;&#x9762;</span></span><br><span class="line">             <span class="built_in">window</span>.location.href = <span class="string">&quot;http://www.baidu.com&quot;</span>;</span><br><span class="line">        }</span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">        {</span><br><span class="line">            setTimeout(goIndexPage,speed);  <span class="comment">//  &#x9012;&#x5F52;&#x8C03;&#x7528;  &#x81EA;&#x5DF1;&#x8C03;&#x7528;&#x81EA;&#x5DF1;</span></span><br><span class="line">        }</span><br><span class="line">    }</span><br></pre></td></tr></table></figure>
<h2 id="&#x81EA;&#x52A8;&#x8DF3;&#x8F6C;&#x9875;&#x9762;"><a href="#&#x81EA;&#x52A8;&#x8DF3;&#x8F6C;&#x9875;&#x9762;" class="headerlink" title="&#x81EA;&#x52A8;&#x8DF3;&#x8F6C;&#x9875;&#x9762;"></a>&#x81EA;&#x52A8;&#x8DF3;&#x8F6C;&#x9875;&#x9762;</h2><p>window.location.href = &#x201D;<a href="http://jokerliang.cn&#x201D;" target="_blank" rel="noopener">http://jokerliang.cn&#x201D;</a></p>
<h2 id="arguments-&#x5BF9;&#x8C61;"><a href="#arguments-&#x5BF9;&#x8C61;" class="headerlink" title="arguments &#x5BF9;&#x8C61;"></a>arguments &#x5BF9;&#x8C61;</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">arguments</span>.length;  &#x8FD4;&#x56DE;&#x7684;&#x662F;  &#x5B9E;&#x53C2;&#x7684;&#x4E2A;&#x6570;&#x3002;    </span><br><span class="line">&#x4F46;&#x662F;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;&#x6709;&#x8BB2;&#x7A76;&#xFF0C;&#x4ED6;&#x53EA;&#x5728;&#x6B63;&#x5728;&#x4F7F;&#x7528;&#x7684;&#x51FD;&#x6570;&#x5185;&#x4F7F;&#x7528;&#x3002; </span><br><span class="line"><span class="built_in">arguments</span>.callee;    </span><br><span class="line">&#x8FD4;&#x56DE;&#x7684;&#x662F;&#x6B63;&#x5728;&#x6267;&#x884C;&#x7684;&#x51FD;&#x6570;&#x3002; &#x4E5F;&#x662F;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x4F7F;&#x7528;&#x3002; &#x5728;&#x4F7F;&#x7528;&#x51FD;&#x6570;&#x9012;&#x5F52;&#x8C03;&#x7528;&#x65F6;&#x63A8;&#x8350;&#x4F7F;&#x7528;<span class="built_in">arguments</span>.callee&#x4EE3;&#x66FF;&#x51FD;&#x6570;&#x540D;&#x672C;&#x8EAB;&#x3002;</span><br></pre></td></tr></table></figure>
<h2 id="&#x83B7;&#x53D6;&#x5B57;&#x7B26;&#x4F4D;&#x7F6E;&#x65B9;&#x6CD5;"><a href="#&#x83B7;&#x53D6;&#x5B57;&#x7B26;&#x4F4D;&#x7F6E;&#x65B9;&#x6CD5;" class="headerlink" title="&#x83B7;&#x53D6;&#x5B57;&#x7B26;&#x4F4D;&#x7F6E;&#x65B9;&#x6CD5;"></a>&#x83B7;&#x53D6;&#x5B57;&#x7B26;&#x4F4D;&#x7F6E;&#x65B9;&#x6CD5;</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">charAt&#xFF0C;&#x83B7;&#x53D6;&#x76F8;&#x5E94;&#x4F4D;&#x7F6E;&#x5B57;&#x7B26;&#xFF08;&#x53C2;&#x6570;&#xFF1A; &#x5B57;&#x7B26;&#x4F4D;&#x7F6E;&#xFF09; </span><br><span class="line">charCodeAt&#x83B7;&#x53D6;&#x76F8;&#x5E94;&#x4F4D;&#x7F6E;&#x5B57;&#x7B26;unicode&#x7F16;&#x7801;&#xFF08;&#x53C2;&#x6570;&#xFF1A; &#x5B57;&#x7B26;&#x4F4D;&#x7F6E;&#xFF09;</span><br><span class="line"><span class="keyword">var</span> txt = &#x201C;abcedf&#x201D;;     </span><br><span class="line">&#x6BD4;&#x5982;&#xFF0C;  txt.charAt(<span class="number">4</span>);    &#x7D22;&#x5F15;&#x53F7;&#x4E00;&#x5B9A;&#x662F;&#x4ECE;<span class="number">0</span>&#x5F00;&#x59CB;    &#x8FD4;&#x56DE;&#x7684;&#x7ED3;&#x679C;&#x662F; d</span><br><span class="line">&#x6211;&#x4EEC;&#x6839;&#x636E;&#x6211;&#x4EEC;&#x8F93;&#x5165;&#x7684; &#x4F4D;&#x6570; &#x8FD4;&#x56DE;&#x76F8;&#x5E94;&#x7684; &#x5B57;&#x7B26; &#x3002;</span><br><span class="line">unicode&#x7F16;&#x7801;  &#x662F;&#x6211;&#x4EEC;&#x5B57;&#x7B26;&#x7684;&#x5B57;&#x7B26;&#x7684;&#x552F;&#x4E00;&#x8868;&#x793A;</span><br></pre></td></tr></table></figure>
      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/JavaScript/" rel="tag"># JavaScript</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/11/29/前端JavaScript（一）/" rel="next" title="前端JavaScript（一）">
                <i class="fa fa-chevron-left"></i> 前端JavaScript（一）
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/11/30/Android基础（一）/" rel="prev" title="Android基础（一）">
                Android基础（一） <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/me.jpg"
               alt="JokerLiang" />
          <p class="site-author-name" itemprop="name">JokerLiang</p>
          <p class="site-description motion-element" itemprop="description">永远年轻，永远热泪盈眶。</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">61</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/LoverJoker" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.zhihu.com/people/lover-easy-7/activities" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/2292572142/profile?rightmod=1&wvr=6&mod=personinfo" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  微博
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Friends
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.knight.ac.cn/" title="Knight" target="_blank">Knight</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://lzllzl.cn/" title="Zayvion" target="_blank">Zayvion</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://chen97.com/" title="Chens" target="_blank">Chens</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#设置节点属性"><span class="nav-number">1.</span> <span class="nav-text">设置节点属性</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#获取节点属性"><span class="nav-number">1.1.</span> <span class="nav-text">获取节点属性</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#设置节点属性-1"><span class="nav-number">1.2.</span> <span class="nav-text">设置节点属性</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#删除某个属性"><span class="nav-number">1.3.</span> <span class="nav-text">删除某个属性</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#日期函数"><span class="nav-number">2.</span> <span class="nav-text">日期函数</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#声明日期"><span class="nav-number">2.1.</span> <span class="nav-text">声明日期</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#常用的日期的方法"><span class="nav-number">2.2.</span> <span class="nav-text">常用的日期的方法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#倒计时"><span class="nav-number">2.3.</span> <span class="nav-text">倒计时</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#定时器"><span class="nav-number">3.</span> <span class="nav-text">定时器</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#setInterval"><span class="nav-number">3.1.</span> <span class="nav-text">setInterval()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#setTimeout"><span class="nav-number">3.2.</span> <span class="nav-text">setTimeout()</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#自动跳转页面"><span class="nav-number">4.</span> <span class="nav-text">自动跳转页面</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#arguments-对象"><span class="nav-number">5.</span> <span class="nav-text">arguments 对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#获取字符位置方法"><span class="nav-number">6.</span> <span class="nav-text">获取字符位置方法</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">JokerLiang</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	




  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
      search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').toggle();
    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';
      $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = $( "entry", xmlResponse ).map(function() {
            return {
              title: $( "title", this ).text(),
              content: $("content",this).text(),
              url: $( "url" , this).text()
            };
          }).get();
          var $input = document.getElementById(search_id);
          var $resultContent = document.getElementById(content_id);
          $input.addEventListener('input', function(){
            var matchcounts = 0;
            var str='<ul class=\"search-result-list\">';
            var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
            $resultContent.innerHTML = "";
            if (this.value.trim().length > 1) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var content_index = [];
                var data_title = data.title.trim().toLowerCase();
                var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                var data_url = decodeURIComponent(data.url);
                var index_title = -1;
                var index_content = -1;
                var first_occur = -1;
                // only match artiles with not empty titles and contents
                if(data_title != '') {
                  keywords.forEach(function(keyword, i) {
                    index_title = data_title.indexOf(keyword);
                    index_content = data_content.indexOf(keyword);
                    if( index_title >= 0 || index_content >= 0 ){
                      isMatch = true;
                      if (i == 0) {
                        first_occur = index_content;
                      }
                    }

                  });
                }
                // show search results
                if (isMatch) {
                  matchcounts += 1;
                  str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                  var content = data.content.trim().replace(/<[^>]+>/g,"");
                  if (first_occur >= 0) {
                    // cut out 100 characters
                    var start = first_occur - 20;
                    var end = first_occur + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if(start == 0){
                      end = 50;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    var match_content = content.substring(start, end);
                    // highlight all keywords
                    keywords.forEach(function(keyword){
                      var regS = new RegExp(keyword, "gi");
                      match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                    });

                    str += "<p class=\"search-result\">" + match_content +"...</p>"
                  }
                  str += "</li>";
                }
              })};
            str += "</ul>";
            if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
            if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
            $resultContent.innerHTML = str;
          });
          proceedsearch();
        }
      });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".popoverlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>


  

  

  

  


</body>
</html>
